import { useI18n } from "vue-i18n";
import { getCurrentInstance } from "vue";
export const getBatteryPic = (e) => {
	e = e > 100 ? 100 : e;
	e = e < 0 ? 0 : e;
	return parseInt(e / 30) + 1;
};

export const getBatteryColor = (e) => {
	const colorJson = ["#E34D59", "#ED7B2F", "#52D668", "#52D668"];
	return colorJson[getBatteryPic(e) - 1];
};

export const getStatus = (ids: number) => {
	const { t } = useI18n();
	let status = [
		t("device.status.0"),
		t("device.status.1"),
		t("device.status.2"),
		t("device.status.3"),
		t("device.status.4"),
		t("device.status.5"),
		t("device.status.6"),
		t("device.status.7"),
		t("device.status.8"),
		t("device.status.9"),
		t("device.status.10"),
		t("device.status.11"),
		t("device.status.12"),
		t("device.status.13"),
		t("device.status.14"),
		t("device.status.15"),
		t("device.status.16"),
		t("device.status.17"),
		t("device.status.18"),
		t("device.status.19"),
	];
	return status[ids - 1];
};
// 获取设备状态颜色
export const getStatusColor = (ids: number) => {
	let status = [
		"#0084FC",
		"#0084FC",
		"#0084FC",
		"#0084FC",
		"#ED7B2F",
		"#E34D59",
		"#ED7B2F",
		"#ED7B2F",
		"#0084FC",
		"#0084FC",
		"#ED7B2F",
		"#ED7B2F",
		"#ED7B2F",
		"#ED7B2F",
		"#0084FC",
		"#ED7B2F",
		"#ED7B2F",
		"#ED7B2F",
		"#ED7B2F",
		"#ED7B2F",
	];
	return status[ids - 1];
};

// 获取设备对应图片
export const getDeviceImg = (type: string) => {
	const instance: any = getCurrentInstance();
	let version = instance.$appVersion;
	if (version === "xz") {
		return "device_xz";
	} else {
		if (type === "XGYH") {
			return "device_xgyh";
		} else if (type === "LCYH") {
			if (version === "sin") return "device_lcyh_sin";
			return "device_lcyh";
		} else {
			return "device_other";
		}
	}
};
//获取设备挡板
export const getDamBoard = (val: string) => {
	const { t } = useI18n();
	let rubber = [
		{ name: "small", value: t("device.rubber.small") },
		{ name: "median", value: t("device.rubber.median") },
		{ name: "big", value: t("device.rubber.big") },
		{ name: "huge", value: t("device.rubber.huge") },
		{ name: "auto", value: t("device.rubber.huge") },
	];
	for (let i = 0; i < rubber.length; i++) {
		if (val === rubber[i].name) {
			return rubber[i].value;
		}
	}
};
// 获取设备定位状态
export const getLocation = (val: any) => {
	let location = [
		{ gps: 0, value: "open" },
		{ gps: 1, value: "closed" },
		{ gps: -1, value: "lost" },
	];
	for (let i = 0; i < location.length; i++) {
		if (val === location[i].gps) {
			return location[i].value;
		}
	}
};
// 获取设备电量
export const getPower = (power: number) => {
	if (power >= 0 && power <= 20) {
		return "1";
	} else if (power > 20 && power <= 50) {
		return "2";
	} else if (power > 50 && power <= 100) {
		return "3";
	} else {
		return "4";
	}
};
// 默认导出所有方法
export default {
	getBatteryPic,
	getBatteryColor,
	getStatus,
	getStatusColor,
	getDeviceImg,
	getDamBoard,
	getLocation,
	getPower,
};
